﻿namespace EasyGo.Web.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;
    using EasyGo.Domain.Projections;
    using EasyGo.Services;
    using EasyGo.Web.Models;
    using EasyGo.Domain.Model;
    using EasyGo.Web.Authentication;
    using System.Web.Security;

    public class UserAccountController : ApiController
    {
        private readonly IUserAccountService service;

        private readonly IAuthenticationService authService;

        public UserAccountController(IUserAccountService service, IAuthenticationService authService)
        {
            this.service = service;
            this.authService = authService;
        }

        public IEnumerable<ListUser> Get()
        {
            return this.service.GetAll();
        }

        // GET api/useraccount/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/useraccount
        public HttpResponseMessage Post(UserAccount value)
        {
            if (!ModelState.IsValid)
            {
                return new HttpResponseMessage(HttpStatusCode.BadRequest);
            }
            MembershipCreateStatus inserted = authService.CreateUser(value);

            if (inserted == MembershipCreateStatus.Success)
            {
                return Request.CreateResponse(HttpStatusCode.Created);
            }
            return Request.CreateErrorResponse(HttpStatusCode.BadRequest, inserted.ToString());
        }

        // PUT api/useraccount/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/useraccount/5
        public void Delete(int id)
        {
        }
    }
}
